<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script th:src="@{/layui/layui.js}" type="text/javascript"></script>
		<link th:href="@{/layui/css/layui.css}" rel="stylesheet" />
	</head>
	<body>
		<div class="layui-container" style="margin: 10px 0px; ">
			<form class="layui-form layui-form-pane">
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">信息类型</label>
						<div class="layui-input-inline" style="width: 225px;">
							<input type="radio" name="type" value="0" title="短信" checked/>
							<input type="radio" name="type" value="1" title="邮件" />
						</div>	
						
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">信息接收人</label>
						<div class="layui-input-inline">
							<input type="radio" name="accept" value="member" lay-filter="accept" title="员工" checked/>
							<input type="radio" name="accept" value="vip" lay-filter="accept" title="会员" />
						</div>	
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block" style="border: 1px solid #708090;">
						<div>
							<input type="radio" name="acceptType" lay-filter="member" value="all" title="所有员工" checked/>
							<input type="radio" name="acceptType" lay-filter="member" value="some" title="指定员工"/>
							<hr id="hr" style="display: none;"/>
							<div id="acceptUser" style="display: none;">

							</div>
						</div>
					</div>	
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">信息标题</label>
					<div class="layui-input-block">
						<input type="text" class="layui-input" name="title" />
					</div>	
				</div>
				<div class="layui-form-item layui-form-text">
					<label class="layui-form-label">信息内容</label>
					<div class="layui-input-block">
						<textarea id="demo" class="layui-textarea" name="content"></textarea>
					</div>	
				</div>
				<div class="layui-form-item" style="display: none;">
					<div class="layui-input-block">
						<a class="layui-btn" id="submitBtn" lay-submit="" lay-filter="submitBtn">提交</a>
					</div>	
				</div>
			</form>
		</div>
		<script>
			
			var $,form;
			layui.use(['form','jquery','layer'],function(){
				var layer = layui.layer;
					form = layui.form;
					$ = layui.jquery;

				getAllMember();

				form.on('submit(submitBtn)',function (data) {
					var formData = data.field;
					$.ajax({
						type:'post',
						url:'/system/smc/add',
						data:formData,
						dataType:'json',
						success:function (result) {
							layer.msg(result.msg);
							if (result.is){
								top.layer.msg(result.msg);
								let index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);//关闭父页窗口
							}
						}
					})


				})

				
				
				form.on('radio(accept)',function(data){
					var value = data.value;
					var all = "",some="";
					if(value=='member'){
						all="所有员工",some="指定员工";
						getAllMember();
					}else{
						all="所有会员",some="指定会员";
						getAllVip();//TODO
					}
					$('input[value="all"]').attr('title',all).next().find('div').html(all);
					$('input[value="some"]').attr('title',some).next().find('div').html(some);
				})
				form.on('radio(member)',function(data){
					var value = data.value;
					var all = "",some="";
					if(value=='all'){
						$("#hr").hide();
						$("#acceptUser").hide();
					}else{
						$("#hr").show();
						$("#acceptUser").show();
					}
					
				})
			});
			
			function getAllMember() {
				$.ajax({
					type: 'post',
					url:'/system/mc/find',
					data:{
						limit:100
					},
					dataType:'json',
					success:function (result) {
						$('#acceptUser').empty();//清空
						$.each(result.data,function (i,m) {
							var ele = '<input type="checkbox" name="acceptUsers[]" value="'+m.loginName+'" title="'+m.userName+'" />';
							$('#acceptUser').append(ele);
						})
						form.render();//表单刷新
					}
				})
				
			}
			function getAllVip() {
				
			}
			
			function btnSubmit(){
				$('#submitBtn').click();
			}
		</script>
	</body>
</html>
